import request from "@/service/request";
import requestAly from "@/service/requestAly";
// 获取年龄列表
const getAgeList = (query: any) => {
  return request({
    url: "/course/age/page",
    method: "get",
    params: query,
  });
};

// 获取场景分类列表
const getSceneList = () => {
  return request({
    url: "/course/scene/list",
    method: "get",
  });
};

// 获取二级分类列表
const getSecondScene = (id: string) => {
  return request({
    url: "/course/category/listByScene/" + id+ `?haveLabel=${'1'}`,
    method: "get",
  });
};

// 获取标签
const getTagList = (id: string) => {
  return request({
    url: "/course/label/listByCategory/" + id,
    method: "get",
  });
};

// 获取课程详情
const getCourseDetail = (id: string) => {
  return request({
    url: "/course/course/" + id,
    method: "get",
  });
};

// 新增课程
const addCourse = (query: any) => {
  return request({
    url: "/course/course",
    method: "post",
    data: query,
  });
};

// 修改课程详情
const  updateCourse = (query: any) => {
  return request({
    url: `/course/course/edit`,
    method: "put",
    data: query
  });
}

// 获取凭证
const getOssAuth = (query: any) => {
  return request({
    url: "/system/oss/uploadAuth",
    method: "get",
    params: query
  });
};

// 文件上传到OSS
const postToOSS = (formData: any) => {
  return requestAly({
    url: ``,
    method: "post",
    data: formData,
  });
};

// 私有资源
const getSelfCourseResource = (query: any) => {
  return request({
    url: "/course/resource/self/list",
    method: "get",
    params: query,
  });
};

// 公共资源
const getPublicCourseResource = (query: any) => {
  return request({
    url: "/course/resource/open/list",
    method: "get",
    params: query,
  });
};

// 所有资源（管理员）
const getAllCourseResource = (query: any) => {
  return request({
    url: `/course/resource/list`,
    method: "get",
    params: query,
  });
};

// 获取播放凭证
const getPlayAuth = (id: string) => {
  return request({
    url: "/course/resource/play/" + id,
    method: "get",
  });
};
// 新增章节
const addChapter = (query: any) => {
  return request({
    url: "/course/section",
    method: "post",
    data: query
  });
};

// 获取章节列表
const getChapterList = (query: any) => {
  return request({
    url: "/course/section/list",
    method: "get",
    params: query
  });
}

// 删除章节
const delChapter = (id: string) => {
  return request({
    url: "/course/section/"+id,
    method: "delete",
  });
}

// 更新章节信息
const updataChpater = (query: any) => {
  return request({
    url: "/course/section/edit",
    method: "put",
    data: query
  });
}

// 获取章节详情
const getChapterDetail = (id: string) => {
  return request({
    url: "/course/section/"+id,
    method: "get",
  });
}

// 绑定课程介绍
const linkImg = (query: any) => {
  return request({
    url: "/course/course/img",
    method: "post",
    data: query
  });
}

// 绑定封面
const linkCover = (query: any) => {
  return request({
    url: `/course/course/cover?courseId=${query.courseId}&type=${query.type}&url=${query.url}`,
    method: "put",
  });
}

// 交换章节
const exchange = (query: any) => {
  return request({
    url: `/course/section/exchange`,
    method: "post",
    params:query
  });
}

// 获取key
const getUploadAuth = (query: any) => {
  return request({
    url: "/course/resource",
    method: "post",
    data: query,
  });
};
export {
  getAgeList,
  getSceneList,
  getSecondScene,
  getTagList,
  getCourseDetail,
  addCourse,
  updateCourse,
  getOssAuth,
  postToOSS,
  getSelfCourseResource,
  getPublicCourseResource,
  getAllCourseResource,
  getPlayAuth,
  addChapter,
  getChapterList,
  delChapter,
  updataChpater,
  getChapterDetail,
  linkImg,
  linkCover,
  exchange,
  getUploadAuth
};
